package com.ruoyi.miniapp.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.map.SoMap;
import com.ruoyi.miniapp.domain.TMiniHistory;
import com.ruoyi.miniapp.service.ITMiniHistoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 体重监测历史数据Controller
 *
 * @author ruoyi
 * @date 2025-06-11
 */
@RestController
@RequestMapping("/miniapp/history")
public class TMiniHistoryController extends BaseController
{
    @Autowired
    private ITMiniHistoryService tMiniHistoryService;

    /**
     * 获取体重监测历史数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('miniapp:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tMiniHistoryService.selectTMiniHistoryById(id));
    }

    /**
     * 新增体重监测历史数据
     */
    @PreAuthorize("@ss.hasPermi('miniapp:history:add')")
    @Log(title = "体重监测历史数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMiniHistory tMiniHistory)
    {
        return toAjax(tMiniHistoryService.insertTMiniHistory(tMiniHistory));
    }

    /**
     * 修改体重监测历史数据
     */
    @PreAuthorize("@ss.hasPermi('miniapp:history:edit')")
    @Log(title = "体重监测历史数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMiniHistory tMiniHistory)
    {
        return toAjax(tMiniHistoryService.updateTMiniHistory(tMiniHistory));
    }

    /**
     * 删除体重监测历史数据
     */
    @PreAuthorize("@ss.hasPermi('miniapp:history:remove')")
    @Log(title = "体重监测历史数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tMiniHistoryService.deleteTMiniHistoryByIds(ids));
    }


    /**
     * 查询最近7天的体重监测历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('miniapp:history:query')")
    @GetMapping("/listHistoryData")
    public AjaxResult listHistoryData()
    {
        SoMap so = getRequestSoMap();
        List<TMiniHistory> list = tMiniHistoryService.selectTMiniHistoryList(so);
        return success(list);
    }

    /**
     * 用户数据分析
     */
    @PreAuthorize("@ss.hasPermi('miniapp:history:query')")
    @GetMapping("/historyAnalysis")
    public AjaxResult historyAnalysis()
    {
        SoMap so = getRequestSoMap();
        Map result = tMiniHistoryService.historyAnalysis(so);
        return success(result);
    }

    /**
     * 按照指定月份获取体重监测历史数据
     */
    @PreAuthorize("@ss.hasPermi('miniapp:history:query')")
    @GetMapping(value = "/listByHistory")
    public AjaxResult listByHistory()
    {
        SoMap so = getRequestSoMap();
        List<TMiniHistory> list = tMiniHistoryService.selectHistoryMonth(so);
        return success(list);
    }

}

